package com.example.schoolnewsapp.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.schoolnewsapp.JavaBean.news_info;
import com.example.schoolnewsapp.R;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class NewsDoubleAdapter extends RecyclerView.Adapter<NewsDoubleAdapter.ViewHolder> {
    private final List<news_info> newsList;
    public NewsDoubleAdapter(List<news_info> newsList){
        this.newsList = newsList;
    }
    @NonNull
    @NotNull
    @Override
    public NewsDoubleAdapter.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_double,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull NewsDoubleAdapter.ViewHolder holder, int position) {
        news_info inews = newsList.get(position);
        holder.tv_title.setText(inews.getTitle());
        holder.tv_main.setText(inews.getContext());
        holder.tv_time.setText(inews.getUpdatedAt());

    }

    @Override
    public int getItemCount() {
        return newsList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_title;
        TextView tv_time;
        TextView tv_main;

        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tv_title=itemView.findViewById(R.id.second_tvtitle);
            tv_time=itemView.findViewById(R.id.second_tvtime);
            tv_main=itemView.findViewById(R.id.second_tvmain);
        }
    }
}
